#ifndef __SOFT_I2C_H_
#define __SOFT_I2C_H_

#include "main.h"

typedef enum
{
    SOFT_I2C_1,
    SOFT_I2C_2,
    _SOFT_I2C_MAX /*内部使用*/
};
#define IS_SOFT_ID(id)      (id < _SOFT_I2C_MAX)
#define I2C_WR	0		/* 写控制bit */
#define I2C_RD	1		/* 读控制bit */
#define SOFT_I2C_SCL(id, pin_val)   HAL_GPIO_WritePin(soft_i2c[id].port[0], soft_i2c[id].pin[0], pin_val)
#define SOFT_I2C_SDA(id, pin_val)   HAL_GPIO_WritePin(soft_i2c[id].port[1], soft_i2c[id].pin[1], pin_val)
#define SOFT_I2C_READ(id)           HAL_GPIO_ReadPin(soft_i2c[id].port[1], soft_i2c[id].pin[1])

bool soft_i2c_init(uint8_t id);
void soft_i2c_start(uint8_t id, uint8_t addr);
void soft_i2c_stop(uint8_t id);
uint8_t soft_i2c_write(uint8_t id, uint8_t reg, uint8_t *buf, uint8_t len);
uint8_t soft_i2c_read(uint8_t id, uint8_t reg, uint8_t *buf, uint8_t len);

#endif /*__SOFT_I2C_H_*/